package com.hemaapp.yjnh.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.hemaapp.yjnh.BaseUtil;
import com.hemaapp.yjnh.R;

import xtom.frame.util.XtomToastUtil;

/**
 * 类描述：发货填写快递信息dialog
 * 创建人：GuiyouZhang
 * 创建时间：2016/7/20 16:44
 * 修改备注：
 */
public class DeliveryDialog {

    private Context mContext;
    private Dialog dialog;
    private EditText edtName;
    private EditText edtNum;
    private View.OnClickListener clickListener;

    public DeliveryDialog(Context context) {
        this.mContext = context;
    }

    public void setClickListener(View.OnClickListener clickListener) {
        this.clickListener = clickListener;
    }

    public DeliveryDialog builder() {
        View dialogview = LayoutInflater.from(mContext).inflate(R.layout.dialog_deliver_goods_info, null);
        dialog = new Dialog(mContext, R.style.CustomizeDialogStyle);
        dialog.setContentView(dialogview);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        edtName = (EditText)dialogview.findViewById( R.id.et_express_name );
        edtNum = (EditText)dialogview.findViewById( R.id.et_express_num );
        BaseUtil.setEmojiFilter(edtName);
        TextView tvCancel = (TextView)dialogview.findViewById( R.id.tv_cancel );
        TextView tvOk = (TextView)dialogview.findViewById( R.id.tv_ok );
        tvCancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog.cancel();
            }
        });
        tvOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickListener != null)
                    clickListener.onClick(v);
            }
        });
        Window dialogWindow = dialog.getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.x = 0;
        lp.y = 0;
        lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
        return this;
    }

    public void show() {
        dialog.show();
    }

    public void dismiss() {
        dialog.dismiss();
    }

    public String getExpressName() {
        return edtName.getText().toString().trim();
    }

    public String getExpressNum() {
        return edtNum.getText().toString().trim();
    }

    public void initialize() {
        edtName.setText("");
        edtNum.setText("");
    }
}
